﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace ASteroids
{
    class BubbelBackground
    {
        private List<Sprite> stars = new List<Sprite>();
        private Point ScreenSize = new Point(1024,768);
        private Random rand = new Random();
        private Color[] colors = { Color.White};

        float distance;

        public BubbelBackground(
            int screenWidth,
            int screenHeight,
            int starCount,
            Vector2 starVelocity,
            Texture2D texture,
            Rectangle frameRectangle) 
        {
            this.ScreenSize.X = screenWidth;
            this.ScreenSize.Y = screenHeight;

            
            for (int x = 0; x < starCount; x++) {
                distance = (float)(rand.NextDouble() + 0.1f) * 1.2f;

                stars.Add(new Sprite(
                    new Vector2(rand.Next(0, ScreenSize.X), rand.Next(0, ScreenSize.Y)),
                    texture,
                    frameRectangle,
                    starVelocity, distance));
                Color bubbleColor = Color.White;

                bubbleColor.A = (byte)(255/distance);
                
                stars[stars.Count - 1].TintColor = bubbleColor;
                
            }
        }

        public void Update(GameTime gameTime)
        {
            foreach (Sprite star in stars)
            {
                star.Update(gameTime);
                if (star.Location.Y + star.BoundingBoxRect.Height < 0)
                {
                    
                    star.Location = new Vector2(rand.Next(0, ScreenSize.X), ScreenSize.Y);
                    star.Scale = (float)(rand.NextDouble() + 0.1f) * 1.2f;
                    
                }
            }
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            foreach (Sprite star in stars)
            {
                star.Draw(spriteBatch);
            }
        }
    }
}
